﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AISFMIOperator
{
    public partial class AddFacilityForm : Form
    {
        public AddFacilityForm()
        {
            InitializeComponent();
            RefreshAllData();
        }

        private void RefreshAllData()
        {
            city.DataSource = City.GetAllCities();
            city.DisplayMember = "CityFullName";

            facilitytype.DataSource = FacilityType.GetAllFacilityTypes();
            facilitytype.DisplayMember = "FacilityTypeName";
        }

        private void AddFacilityForm_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Address addr = new Address();
            addr.AddressID = 0;
            addr.City = (City)city.SelectedItem;
            addr.Addr = address.Text.Trim();
            addr.PostIndex = int.Parse(post_index.Text.Trim());

            addr.Save();
            
            Facility f = new Facility();
            f.FacilityID = 0;
            f.FacilityName = facilityname.Text.Trim();
            f.FacilityType = (FacilityType)facilitytype.SelectedItem;
            f.Address = addr;
            f.Description = description.Text.Trim();

            f.Save();

            this.Close();
        }
    }
}
